package com.example.core.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.example.core.domain.R;
import com.example.core.domain.TableDataInfo;
import com.github.pagehelper.PageInfo;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-11-24
 * Time: 23:22
 */

public class BaseController {
    /**
     *
     * @param rows 数据库结果
     * @return 返回响应
     */
    public R<Void> toR(int rows) {
        return rows > 0 ? R.ok() : R.fail();
    }

    public R<Void> toR(Boolean result) {
        return result ? R.ok() : R.fail();
    }

    public TableDataInfo getTableDataInfo(List<?> list) {
        //list == null || list.isEmpty()
        if (CollectionUtil.isEmpty(list)) {
            return TableDataInfo.empty();
        }
//        new PageInfo<>(list).getTotal(); //获取符合查询条件的数据的总数
//        return TableDataInfo.success(list, list.size());
        return TableDataInfo.success(list, new PageInfo<>(list).getTotal());
    }
}
